package com.xyoto.takeawayBusiness.utils;

import com.xyoto.takeawayBusiness.constant.OrdersStatus;
import com.xyoto.takeawayBusiness.entity.Orders;
import com.xyoto.takeawayBusiness.enums.Code;
import com.xyoto.takeawayBusiness.enums.CommonEnum;
import com.xyoto.takeawayBusiness.enums.OrderEnum;
import com.xyoto.takeawayBusiness.exception.ExceptionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName: 参数校验工具类
 * @Author: 挽风
 * @Date: 2022
 * @Copyright: 2022 by 挽风
 * @Description:
 **/
public class JudgeParamUtils {

    /**
     * 订单状态范围
     */
    private static final Short[] ORDER_STATUS_RANGE = new Short[]{
            OrdersStatus.PROCESSING, OrdersStatus.DELIVERED, OrdersStatus.DELIVERYING, OrdersStatus.INHAND,
            OrdersStatus.COMPLETED, OrdersStatus.REJECTED, OrdersStatus.REFUND_FAILED, OrdersStatus.CANCELLED,
            OrdersStatus.PAID, OrdersStatus.UNPAID, OrdersStatus.REFUND_NOW, OrdersStatus.CUSTOMER_SERVICE_INTERVENTION
    };



    /**
     * 校验Integer多参数类型
     * @param param
     */
    public static void judgeIntegerParam(Integer...param){
        for (Integer item : param) {
            if (item != null && item <= 0){
                ExceptionUtils.error(CommonEnum.REQUEST_PARAM_ERROR);
            }
        }
    }

    public static void judgeIntegerParam(Integer param, Code code){
        if (param == null || param <= 0){
            ExceptionUtils.error(code);
        }
    }

    /**
     * 校验订单状态范围
     * @param status
     */
    public static void judgeOrderStatus(Short status) {
        if (status <= 0){
            ExceptionUtils.error(OrderEnum.ORDER_STATUS_ERROR);
        }
        List<Short> rangeList = Arrays.asList(ORDER_STATUS_RANGE);
        if (!rangeList.contains(status)){
            ExceptionUtils.error(OrderEnum.ORDER_STATUS_ERROR);
        }
    }
}
